#ifndef _USER_CFG_H_
#define _USER_CFG_H_
#include "sys.h"
#include "sys_cfg_depend.h"
#include "adp_env.h"
#include "ebm_env.h"

#define SUPER_PASSWORD 2919

typedef struct _CFG_TYPE{
	unsigned char save_head_flag;
	unsigned char local_ip[4];
	unsigned char remote_ip[4];
    unsigned char ota_ip[4];
	unsigned char gateway[4];
	unsigned char mask[4];
	unsigned char mac[6];
	unsigned char areaid[6];
	unsigned char	Logicaddr[6];
	unsigned char	phyaddr[6];
	unsigned char  EncodeMode;
	unsigned char PType;
	unsigned char vol; 			// 音量数据
	unsigned char vol_JT; 		// 监听音量
	unsigned char vol_max; 		// 最大音量
	unsigned char HEART_TIMEOUT_PERIOD; //设置终端重启时间
	unsigned char flgAmplifier;
	
	unsigned char language0;   	// 显示语言数据
	unsigned char dbg_lvl;		// 配置打印等级
	unsigned char dbg_cpu_usage;	// CPU统计开关
	unsigned char backlinght;
	unsigned char LcdPlayType;
	unsigned char sms_passw_check;// 播放需要密码
	unsigned char sms_replay;		// 回短信

	unsigned char  PSip[4];
	unsigned short PSport;
	unsigned short local_port;
	unsigned short remote_port;
    unsigned short ota_port;
	unsigned short CtlPID;
	unsigned short AudioPID;
	unsigned short PNUM;
    unsigned short ECODE_RATE;        //编码码率
	unsigned int user_passw;		//用户密码
	struct ebm_env ebm;
    struct adp_env adp;
	unsigned short reserve1;			//保留1
	unsigned short reserve2;			//保留2
	unsigned short reserve3;			//保留3
	unsigned short reserve4;			//保留4
	unsigned int  save_end_flag;
}CFG_TYPE;	

#define CFG_SIZE sizeof(CFG_TYPE)				//长度
#define CPS_WORD_SIZE ((sizeof(CPS_TYPE)+3)/4)	

extern const CFG_TYPE* p_readcfg;
extern CFG_TYPE *p_wcfg;

void usercfg_init(void);
void usercfg_set_default(void);
void usercfg_handle_loop(void);
void user_reboot(unsigned char nsec);


#define usercfg_str_remote_ip(str)   _set_ip(str,p_wcfg->remote_ip)
#define usercfg_str_local_ip(str)    _set_ip(str,p_wcfg->local_ip)
#define usercfg_str_mask(str)    _set_ip(str,p_wcfg->mask)
#define usercfg_str_gateway(str) _set_ip(str,p_wcfg->gateway)
#define usercfg_str_PSip(str)    _set_ip(str,p_wcfg->PSip)

#define syscfg_mac(str)     _set_6bytes_mac(str,p_wcfg->mac)
#define syscfg_logicid(str) _set_6bytes_mac(str,p_wcfg->Logicaddr)
#define syscfg_phyid(str)   _set_6bytes_mac(str,p_wcfg->phyaddr)


#define syscfg_remote_ip_raw(ip) set_val_array(p_wcfg->remote_ip, ip, 4)
#define syscfg_local_ip_raw(ip) set_val_array(p_wcfg->local_ip, ip, 4)
#define syscfg_mask_raw(ip) set_val_array( p_wcfg->mask, ip, 4)
#define syscfg_gateway_raw(ip) set_val_array(p_wcfg->gateway, ip, 4);
#define syscfg_PSip_raw(ip) set_val_array(p_wcfg->PSip, ip, 4);

#define syscfg_mac_raw(ip) set_val_array( p_wcfg->mac, ip,6);
#define syscfg_PSport(val) set_val_u16(val, &p_wcfg->PSport)
#define syscfg_HEART_TIMEOUT_PERIOD(val) set_val_u8(val, &p_wcfg->HEART_TIMEOUT_PERIOD)
#define syscfg_remote_port(val) set_val_u16(val, &p_wcfg->remote_port)
#define syscfg_local_port(val) set_val_u16(val, &p_wcfg->local_port)
#define syscfg_Logicaddr(a) set_val_array(p_wcfg->Logicaddr, a, 6);
#define syscfg_LockFeqAddr(a) set_val_array(p_wcfg->phyaddr, a, 6);
#define syscfg_CtlPID(val) set_val_u16(val, &p_wcfg->CtlPID)
#define syscfg_AudioPID(val) set_val_u16(val, &p_wcfg->AudioPID)
#define syscfg_PNUM(val) set_val_u16(val, &p_wcfg->PNUM)
#define syscfg_ECODE_RATE(val) set_val_u16(val, &p_wcfg->ECODE_RATE)
#define syscfg_PType(val) set_val_u8(val, &p_wcfg->PType)
#define usercfg_set_vol(val) set_val_u8(val, &p_wcfg->vol)
#define syscfg_EncodeMode(val) set_val_u8(val, &p_wcfg->EncodeMode)

#define syscfg_ota_sip_get()    p_readcfg->ota_ip
#define syscfg_ota_sip_set(ip) set_val_array(p_wcfg->ota_ip, ip, 4)

#define syscfg_ota_port_get()   p_readcfg->ota_port
#define syscfg_ota_port_set(val)    set_val_u16(val, &p_wcfg->ota_port)





const unsigned char* read_serid(void);

#endif 

